#include "header.h"

double total = 1024.0;		// 假设任务文件是1024MB
double speed = 1.0;			// 假设每秒下载/上传1MB

void Download(callback_t cb)
{
	double cur = 0.0;

	for (; cur <= total;)
	{
		cb(total, cur);		// 使用函数指针，解耦
		usleep(1000);		// 模拟下载逻辑
		cur += speed;		// 已下载量
	}
	printf("\ndownload %.2lfMB Done\n", cur > total ? total : cur);
}

void Upload(callback_t cb)
{
	double cur = 0.0;

	for (; cur <= total;)
	{
		cb(total, cur);
		usleep(1000);		// 模拟上传逻辑
		cur += speed;		// 已上传量
	}
	printf("\nupload %.2lfMB Done\n", cur > total ? total : cur);
}

int main()
{
	//process_v1();
	Download(FlushProcess);// 使用函数指针，解耦
	Download(FlushProcess);
	Upload(FlushProcess);
	Upload(FlushProcess);

	return 0;
}
